//
//  Feedback1ViewController.m
//  CarLifes
//
//  Created by yu on 2017/8/12.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "Feedback1ViewController.h"
#import "FeedBackTextView.h"
#import "NSString+JudgeString.h"
#import "JDStatusBarNotification.h"

@interface Feedback1ViewController ()

@property (weak, nonatomic) IBOutlet FeedBackTextView *textField;
@property (weak, nonatomic) IBOutlet UITextField *contactTextField;
@property (weak, nonatomic) IBOutlet UITextField *mobileTextField;
@property (weak, nonatomic) IBOutlet UITextField *tencentTextField;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end

@implementation Feedback1ViewController

- (void)setBgView:(UIView *)bgView
{
    _bgView = bgView;
    bgView.layer.borderColor = kTextLightGrayColor.CGColor;
    bgView.layer.borderWidth = 0.5;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"意见反馈";
//    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
//    if (@available(iOS 13.0, *)) {
//        UIColor *bgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
//            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
//                return kBackGroundLightGrayColor;
//            } else {
//                return UIColor.systemBackgroundColor;
//            }
//        }];
//        self.bgView.backgroundColor = bgColor;
//    } else {
//        self.bgView.backgroundColor = kBackGroundLightGrayColor;
//    }
    
    [self setRightItemTitle:@"提交" titleColor:kBaseColor action:@selector(submitAction)];
    
    [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 20.f;
}

- (void)submitAction
{
    [self.textField resignFirstResponder];
    [self.mobileTextField resignFirstResponder];
    [self.contactTextField resignFirstResponder];
    
    if (self.textField.text.length == 0) {
        [MBProgressHUD showToast:@"内容不能为空"];
        return;
    }
    else
    {
        if (self.contactTextField.text.length == 0) {
            [MBProgressHUD showToast:@"联系人必填"];
            return;
        }
        
        if (self.mobileTextField.text.length != 11 || [NSString valiMobile:self.mobileTextField.text] == NO) {
            [MBProgressHUD showToast:@"输入的手机号不合法"];
            return;
        }
    }

//    [JDStatusBarNotification showWithStatus:@"正在提交" styleName:JDStatusBarStyleDefault];
    [self.requestTool feedbackByInfo:self.textField.text contact:self.contactTextField.text phone:self.mobileTextField.text app:self.tencentTextField.text success:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [JDStatusBarNotification showWithStatus:@"提交成功" dismissAfter:2.0 styleName:JDStatusBarStyleSuccess];
            [self.navigationController popViewControllerAnimated:YES];
        });
    } failure:^(NSError *error) {
        PPLog(@"feedback error = %@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
